<template>
  <div class="trade-container">
    <div style="margin-bottom: 10px">
      <span>查询条件：</span>
      <el-select placeholder="Select" v-model="searchValue" value-key="id" size="large" style="width: 240px;height: 40px">
        <el-option v-for="item in searchList.data" :key="item.id" :label="item.label" :value="item.value"/>
      </el-select>
      <el-input v-model="keyword" style="width: 240px;margin: 0 10px;height: 40px" placeholder="请输入" />
      <el-button style="margin-left: 10px" type="primary" @click="searchData">查询</el-button>
      <el-button style="margin-left: 10px" type="primary" @click="resetData">重置</el-button>
    </div>
    <div style="padding: 10px;background-color: #ffffff">
      <el-select placeholder="Select" v-model="templateValue" value-key="id" size="large" style="width: 240px" @change="templateChange">
        <el-option v-for="item in templateList.data" :key="item.id" :label="item.templateName" :value="item"/>
      </el-select>
      <div style="display: inline-block;margin-left: 10px">
        <span>二类证：</span>
        <el-select placeholder="Select" v-model="cardTypeTow" clearable value-key="id" size="large" style="width: 240px" @change="cardTypeTowChange">
          <el-option v-for="item in cardTypeTowList.data" :key="item.name" :label="item.name" :value="item.name"/>
        </el-select>
      </div>
      <el-button :icon="RefreshLeft" style="margin-left: 10px" size="small" circle @click="getCheckList" />
      <div style="margin-top: 10px" v-if="(oneFlag === 'false' && twoFlag === 'true' && threeFlag === 'false')">
        <span>查询条件：</span>
        <el-select placeholder="Select" v-model="keywordData" value-key="id" size="large" style="width: 240px;height: 40px">
          <el-option v-for="item in keywordSearchList.data" :key="item.value" :label="item.label" :value="item.value"/>
        </el-select>
        <el-input v-model="keywordValue" style="width: 240px;margin: 0 10px;height: 40px" placeholder="请输入" />
        <el-button style="margin-left: 10px" type="primary" @click="searchOption">查询</el-button>
        <el-button style="margin-left: 10px" type="primary" @click="resetSearchOption">重置</el-button>
      </div>
    </div>

    <div style="padding: 10px 0" v-if="checkNumber.length">
      <p>待审核数据</p>
      <div style="display: inline-block;margin-right: 10px" v-for="item in checkNumber" :key="item.id">
        <span>{{item.name}}：</span>
        <span>{{item.num}}</span>
      </div>
    </div>
    <el-menu ellipsis class="el-menu-popper-demo" mode="horizontal" :popper-offset="16" :default-active="defaultActive" @select="menuSelect" style="width: 100%;margin-bottom: 20px">
      <el-menu-item index="0">全部</el-menu-item>
      <el-menu-item index="4" v-if="auditName != '超级管理员审核状态'">待审核</el-menu-item>
      <el-menu-item index="5" v-if="auditName != '超级管理员审核状态'">已审核</el-menu-item>
      <el-menu-item index="1">一审拒绝</el-menu-item>
      <el-menu-item index="2">二审拒绝</el-menu-item>
      <el-menu-item index="3">三审拒绝</el-menu-item>
      <el-menu-item index="6">制证数据</el-menu-item>
    </el-menu>
    <div>
      <div style="margin-bottom: 10px">
        <span style="padding-right: 20px">共{{pageTotal}}条</span>
        <span>选择{{selectList.data.length}}条</span>
      </div>
      <div style="margin-bottom: 10px" v-show="(defaultActive === '0' || defaultActive === '3' || defaultActive === '4') && isOperation && auditName != '超级管理员审核状态'">
        <el-button type="primary" @click="checkAllClick(1)">批量审核通过</el-button>
        <el-button style="margin-left: 10px" type="primary" @click="rejectPass(1)">批量审核不通过</el-button>
      </div>
      <div style="margin-bottom: 10px" v-show="defaultActive === '6' && isOperation && auditName != '超级管理员审核状态'">
        <el-button type="primary" @click="sendCard">发证</el-button>
        <el-button style="margin-left: 10px" type="primary" @click="cardCancel">证件注销</el-button>
      </div>
      <el-table ref="multipleTable"
                :data="tableData.data"
                tooltip-effect="dark"
                highlight-selection-row
                max-height="750"
                style="width: 100%"
                :row-class-name="tableRowClassName"
                @row-dblclick="rowDblclick"
                @selection-change="handleSelectionChange">
        <el-table-column type="index" />
        <el-table-column  fixed="left" type="selection" width="55" v-if="(defaultActive === '0' || defaultActive === '4' || defaultActive === '6')&&isOperation&& auditName != '超级管理员审核状态'" />
        <el-table-column prop="uuId" label="批次号" width="130" show-overflow-tooltip></el-table-column>
        <el-table-column prop="userName" label="申请用户" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column v-for="item in templateValue.fieldTemplateList" :key="item.id" :prop="'value.'+item.fieldName" :label="item.notes" width="120" show-overflow-tooltip>
          <template #default="scope" v-if="item.fieldName === 'carLicence' || item.fieldName === 'carLicensef'">
            <img v-lazy="scope.row.value[item.fieldName]" v-show="scope.row.value[item.fieldName]" style="width: 30px;height: 30px" :src="scope.row.value[item.fieldName]" alt="#">
          </template>
<!--          <template #default="scope" v-if="item.fieldName === 'gender'">{{scope.row.value[item.fieldName] === 0 ? '男' : '女'}}</template>-->
        </el-table-column>
        <el-table-column prop="state" label="证件状态" fixed="right" width="100">
          <template #default="scope">{{checkStatusFormattingState(scope.row.state)}}</template>
        </el-table-column>
        <el-table-column prop="oneLevelState" label="一级状态" width="100">
          <template #default="scope">{{checkStatusFormatting(scope.row.oneLevelState)}}</template>
        </el-table-column>
        <el-table-column prop="twoLevelState" label="二级状态" width="100">
          <template #default="scope">{{checkStatusFormatting(scope.row.twoLevelState)}}</template>
        </el-table-column>
        <el-table-column prop="threeLevel" label="三级状态" width="100">
          <template #default="scope">{{checkStatusFormatting(scope.row.threeLevel)}}</template>
        </el-table-column>
        <el-table-column prop="remark" label="拒绝理由" width="100">
        </el-table-column>
        <el-table-column prop="uuId" label="批次号" width="100" show-overflow-tooltip v-if="defaultActive==='6'">
          <template #default="scope">{{scope.row.uuId}}</template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" width="180">
          <template #default="scope">
            <el-link type="success" style="margin-right: 10px" @click="details(scope.row.id)">查看</el-link>
            <div style="display: inline-block" v-show="isOperation">
              <el-link type="primary" style="margin-right: 10px" v-if="(oneFlag === 'false' && twoFlag === 'true' && threeFlag === 'false') && scope.row.twoLevelState === '0'" @click="editInfo(scope.row.id)">修改</el-link>
              <el-link type="primary" style="margin-right: 10px" @click="checkAllClick(0,scope.row.id)" v-if="(defaultActive === '0' || defaultActive === '2' || defaultActive === '4') && (isPassComput(scope.row))" v-show="auditName != '超级管理员审核状态'">通过</el-link>
              <el-link type="warning" style="margin-right: 10px" @click="rejectPass(0,scope.row.id)" v-if="(defaultActive === '0' || defaultActive === '2' || defaultActive === '4') && (isPassComput(scope.row))" v-show="auditName != '超级管理员审核状态'">拒绝</el-link>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div style="margin-top: 10px">
        <el-pagination
            v-model:current-page="pageIndex"
            v-model:page-size="pageSize"
            :page-sizes="[10,30,60,100, 200, 500, 1000]"
            background
            layout="sizes, prev, pager, next"
            :total="pageTotal"
            @size-change="handleSizeChange"
            @current-change="currentChange"
        />
      </div>
    </div>
  </div>
  <!--  // 背审核导出-->
  <el-dialog v-model="showExport" title="背审导出" width="60%" :before-close="exprotClose">
    <div>
      <div style="display:flex;align-items: center">
        <span style="margin-right: 20px">背审状态:</span>
        <el-radio-group v-model="auditState">
          <el-radio value="0">待背审</el-radio>
          <el-radio value="1">背审中</el-radio>
          <el-radio value="2">背审通过</el-radio>
          <el-radio value="3">背审未通过</el-radio>
        </el-radio-group>
      </div>
    </div>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="showExport = false">取消</el-button>
        <el-button type="primary" @click="exportConfirm">导出</el-button>
      </div>
    </template>
  </el-dialog>
  <lookDetails v-if="showDetails" :personId="personId" :templateId="templateValue.id" @showDetailsEmit="showDetailsEmit"></lookDetails>
  <search-all v-if="searchAllShow" :searchValue="searchValue" :keyword="keyword" :loginId="loginId" @handleCloseAll="handleCloseAll"></search-all>
</template>

<script setup>
import { ref, reactive,computed } from "vue";
import {
  _cardCancel,
  _exitData,
  _exitTemplate,
  _getCardTypeSet,
  _getCheckListByCar, _getOptionListByName,
  _getTemplateList, _getUnapproved,
  _personCheck, _personCheckAll, _searchAllList, _sendCardUpdate
} from "../../http/api.js";
import {useRouter} from "vue-router";
import {ElLoading, ElMessage, ElMessageBox} from "element-plus";
import lookDetails from './lookDetails.vue'
import {domesticExport, overseasExport} from "../../utils/excelExport.js";
import {checkStatusFormattingState, checkStatusFormatting, cardTypeTowTable} from "../../utils/index.js"
import {RefreshLeft} from "@element-plus/icons-vue";
import searchAll from '../../components/searchAll.vue'

const router = useRouter();
let loginId = '';
let exhibitionId = '';
const pageTotal = ref(); // 总数
let pageIndex = ref(1);
let pageSize = ref(60);
let oneFlag = ref('');
let twoFlag = ref('');
let threeFlag = ref('');
let auditName = ref('');
const keyword = ref(''); // 关键字
const searchAllShow = ref(false); // 特殊查询处理
// 查询字段
const searchList = reactive({
  data:[
    {label: '车牌号', value: 'carnum' },
    {label: '单位', value: 'carCompany' },
    {label: '车辆联系人', value: 'carName' },
    {label: '车辆联系电话', value: 'carPhone' },
    {label: '批次号', value: 'uuId' }
  ]
})
// 联动查询 车证
const keywordData = ref('');
const keywordSearchList = reactive({
  data:[
    {label: '账号', value: 'account' },
    {label: '车牌号', value: 'carnum' },
  ]
})
// 联动查询值
const keywordValue = ref('');
let t1 = setInterval(() => {
  loginId = sessionStorage.getItem('loginId');
  exhibitionId = sessionStorage.getItem('projectId');

  oneFlag.value = sessionStorage.getItem('oneFlag');
  twoFlag.value = sessionStorage.getItem('twoFlag');
  threeFlag.value = sessionStorage.getItem('threeFlag');
  auditName.value = sessionStorage.getItem('auditName');
  if(loginId&&exhibitionId) {
    clearInterval(t1);
    let sizes = localStorage.getItem('pageSize1');
    if(sizes) {
      pageSize.value = +sizes;
    }
    if(oneFlag.value === 'false' && twoFlag.value === 'true' && threeFlag.value === 'false') {
      searchList.data.push({label: '用户账号', value: 'account'})
    }
    getTemplateList();
    getUnapproved()
  }
},200)


const defaultActive = ref('0'); // 默认展示的列表数据
const templateValue = ref({});
const templateList = reactive({ // 模板列表
  data:[]
})
const tableData = reactive({ // 表格数据
  data:[]
})
const personId = ref('');// 人员数据id
const showDetails = ref(false);
const isPassComput = computed(() => (item) => { //计算属性传递参数
  let isTrue = false;
  let oneLevelState = item.oneLevelState;
  let twoLevelState = item.twoLevelState;
  let threeLevel = item.threeLevel;
  if(oneFlag.value === 'true') {
    isTrue = oneLevelState === '0'
  }
  if(twoFlag.value === 'true') {
    isTrue = twoLevelState === '0'
  }
  if(threeFlag.value === 'true') {
    isTrue = threeLevel === '0'
  }
  return isTrue
})
const selectList = reactive({ // 表格选择的数据
  data:[]
})

const checkNumber = ref([]); // 审核证件的数量
// 二级证件类型
const cardTypeTowList = reactive({
  data:[]
})
// 二级类型选择值
const cardTypeTow = ref('');
// 二级类型标志 1 工作证 2 安保证 3 车证
const flag = ref(3)
// 查询选择的数据
const searchValue = ref('');

// 是否显示操作按钮
const isOperation = ref(true);

// 高亮
const tableRowClassName = ({row}) => {
  if(row.repeatState && row.repeatState === '1') {
    return 'warning-row-it-style'
  }
}
// 行双击时
const rowDblclick = (item) => {
  console.log(item);
}
// 获取字段列表二级选项
const getOptionListByName = (typeString) => {
  if(!typeString) return;
  _getOptionListByName(typeString)
      .then(res => {
        console.log(res);
        if(res.data.ok) {
          let arr = res.data.data;
          console.log(arr);
          cardTypeTowList.data = arr[0].list || [];
        }
      })
      .catch(err => {
        console.log(err);
        ElMessage({message: '网络异常', type: 'error' });
      })
}
// 查询点击
const searchData = () => {
  console.log('searchData');
  console.log(searchValue.value);
  console.log(keyword.value);
  if(!searchValue.value) return ElMessage({message: '请选择查询条件', type: 'warning' });
  if(searchValue.value === 'account') {
    searchAllShow.value = true;
    return ;
  }
  if(!keyword.value) return ElMessage({message: '请输入查询数据', type: 'warning' });
  const loading = ElLoading.service({lock: true, text: 'Loading', background: 'rgba(0, 0, 0, 0.7)'});
  let check = {};
  check[searchValue.value] = keyword.value;
  let params = {
    current: 1,
    size:pageSize.value,
    exhibitionId: exhibitionId,
    templateId:templateValue.value.id,
    userId: loginId
  }
  _searchAllList({ ... params, ... check })
      .then(res => {
        console.log(res);
        loading.close();
        if(res.data.ok) {
          defaultActive.value = '0';
          isOperation.value = false;
          let item = res.data.data;
          pageTotal.value = item.total;
          let records = res.data.data.records;
          tableData.data = records;
        }else {
          ElMessage({message: res.data.msg, type: 'warning' });
        }
      })
      .catch(err => {
        console.log(err);
        loading.close();
      })
}
const handleCloseAll = () => {
  searchAllShow.value = false;
}
// 重置点击
const resetData = () => {
  console.log('resetData');
  searchValue.value = '';
  keyword.value = '';
  isOperation.value = true;
  getCheckList();
}
// 数据选择
const handleSelectionChange = (item) => {
  console.log(item);
  selectList.data = item;
}
//获取模板数据
const getTemplateList = () => {
  templateList.data = [];
  const loading = ElLoading.service({lock: true, text: 'Loading', background: 'rgba(0, 0, 0, 0.7)'});
  _getTemplateList()
      .then(res => {
        console.log(res);
        loading.close();
        if(res.data.ok) {
          let list = res.data.data;
          getCardTypeSet(list)
        }
      })
      .catch(err => {
        console.log(err);
        loading.close();
      })
}
// 获取用户对应证件列表
const getCardTypeSet = (list) => {
  const loading = ElLoading.service({lock: true, text: 'Loading', background: 'rgba(0, 0, 0, 0.7)'});
  _getCardTypeSet(loginId)
      .then(res => {
        console.log(res);
        loading.close();
        if(res.data.ok) {
          let cardTypeList = res.data.data;
          for (let i = 0; i < list.length; i++) {
            if(!list[i].cert) {
              continue;
            }
            for (let j = 0; j < cardTypeList.length; j++) {
              if(list[i].cert.id === cardTypeList[j].certId) {
                if(cardTypeList[j].typeName === '车证') {
                  templateList.data.push({ ... list[i]});
                }
              }
            }
          }
          if(templateList.data.length) {
            templateValue.value = templateList.data[0];
            getCheckList();
            getOptionListByName(templateList.data[0].cert.cardTypeTwo)
          }
        }
      })
      .catch(err => {
        console.log(err);
        loading.close();
      })
}
// 模板切换
const templateChange = (item) => {
  console.log(item);
  console.log(templateValue.value);
  cardTypeTow.value = '';
  defaultActive.value = '0';
  isOperation.value = true;
  getCheckList();
  getOptionListByName(item.cert.cardTypeTwo);
}
// 二级类型选择
const cardTypeTowChange = (val) => {
  console.log(val);
  searchValue.value = '';
  keyword.value = '';
  isOperation.value = true;
  getCheckList()
}
const dataSearchDispose = () => {
  let check = {
    type: ''
  }
  if(oneFlag.value === 'true' && twoFlag.value === 'true' && threeFlag.value === 'true') {
    check.type = 0;
    return check;
  }
  if(oneFlag.value === 'true' && twoFlag.value === 'false' && threeFlag.value === 'false') { // 一审
    check.type = 1;
    return check;
  }
  if(oneFlag.value === 'false' && twoFlag.value === 'true' && threeFlag.value === 'false') { // 二审
    check.type = 2;
    return check;
  }
  if(oneFlag.value === 'false' && twoFlag.value === 'false' && threeFlag.value === 'true') { // 三审
    check.type = 3;
    return check;
  }
}

// 获取人员列表
const getCheckList = () => {
  const loading = ElLoading.service({lock: true, text: 'Loading', background: 'rgba(0, 0, 0, 0.7)'});
  let check = dataSearchDispose()
  let params = {
    current: pageIndex.value,
    size:pageSize.value,
    exhibitionId: exhibitionId,
    templateId:templateValue.value.id,
    cardTypeTwo: cardTypeTow.value,
    flag: flag.value,
    userId: loginId,
    queryStatus: defaultActive.value,
  }
  if(keywordValue.value && keywordData.value) {
    params[keywordData.value] = keywordValue.value;
  }
  if(!flag.value || !cardTypeTow.value) {
    delete params.cardTypeTwo;
    delete params.flag;
  }
  _getCheckListByCar({ ... params, ... check })
      .then(res => {
        console.log(res);
        loading.close();
        if(res.data.ok) {
          let item = res.data.data;
          pageTotal.value = item.total;
          let records = res.data.data.records;
          let arr = [];
          records.forEach(v => {
            let itemValue = v.value;
            let times = itemValue.times;
            if(times) {
              v.value['times'] = JSON.stringify(times);
            }
            arr.push(v);
          })
          tableData.data = arr;

          getUnapproved()
        }else {
          ElMessage({message: res.data.msg, type: 'warning' });
        }
      })
      .catch(err => {
        console.log(err);
        loading.close();
      })
}
// 分页
const currentChange = (index) => {
  pageIndex.value = index;
  getCheckList();
}
const handleSizeChange = (item) => {
  console.log(item);
  pageSize.value = item;
  localStorage.setItem('pageSize1',item)
  getCheckList();
}
// 批量审核通过点击
const checkAllClick = (type,id) => {
  let params = {
    oneLevelState: '1',
    twoLevelState: '1',
    threeLevel: '1',
    type:templateValue.value.cert.type,
  }
  if(oneFlag.value === 'true') {
    delete params.twoLevelState;
    delete params.threeLevel;
    params['oneLevelAccount'] = loginId
  }else if(twoFlag.value === 'true') {
    delete params.oneLevelState;
    delete params.threeLevel;
    params['twoLevelAccount'] = loginId
  }else if(threeFlag.value === 'true'){
    delete params.oneLevelState;
    delete params.twoLevelState;
    params['threeLevelAccount'] = loginId
  }
  let arr = [];
  if(type === 1) {
    if(!selectList.data.length) return ElMessage({message: '请选择审核的数据', type: 'warning' });
    selectList.data.forEach(v => {
      console.log(v);
      if(oneFlag.value === 'true'&&twoFlag.value === 'false'&&threeFlag.value === 'false') { // 一审
        if(v.oneLevelState === '0') {
          arr.push({ ... params, id: v.id })
        }
      }
      if(oneFlag.value === 'false'&&twoFlag.value === 'true'&&threeFlag.value === 'false') { // 二审
        if(v.twoLevelState === '0') {
          arr.push({ ... params, id: v.id })
        }
      }
      if(oneFlag.value === 'false'&&twoFlag.value === 'false'&&threeFlag.value === 'true') { // 三审
        if(v.threeLevel === '0') {
          arr.push({ ... params, id: v.id })
        }
      }
    })
  }else {
    params['id'] = id;
  }
  if(type === 1) {
    if(!arr.length) return ElMessage({message: '选择的数据已审核', type: 'warning' });
  }
  personCheckAll(type === 1?arr:[params]);
}
// 审核不通过点击
const rejectPass = (type,id) => {
  if(type === 1) {
    if(!selectList.data.length) return ElMessage({message: '请选择审核的数据', type: 'warning' });
  }
  ElMessageBox.prompt('请输入驳回理由', '驳回', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    inputPattern:/^./,
    inputErrorMessage: '请输入理由',
  })
      .then(({ value }) => {
        console.log(value);
        let params = {
          remark: value,
          oneLevelState: '2',
          twoLevelState: '2',
          threeLevel: '2',
          type:templateValue.value.cert.type,
        }
        if(oneFlag.value === 'true') {
          delete params.twoLevelState;
          delete params.threeLevel;
          params['oneLevelAccount'] = loginId
        }else if(twoFlag.value === 'true') {
          delete params.oneLevelState;
          delete params.threeLevel;
          params['twoLevelAccount'] = loginId
        }else if(threeFlag.value === 'true'){
          delete params.oneLevelState;
          delete params.twoLevelState;
          params['threeLevelAccount'] = loginId
        }
        let arr = [];
        if(type === 1) {
          selectList.data.forEach(v => {
            if(oneFlag.value === 'true'&&twoFlag.value === 'false'&&threeFlag.value === 'false') { // 一审
              if(v.oneLevelState === '0') {
                arr.push({ ... params, id: v.id })
              }
            }
            if(oneFlag.value === 'false'&&twoFlag.value === 'true'&&threeFlag.value === 'false') { // 二审
              if(v.twoLevelState === '0') {
                arr.push({ ... params, id: v.id })
              }
            }
            if(oneFlag.value === 'false'&&twoFlag.value === 'false'&&threeFlag.value === 'true') { // 三审
              if(v.threeLevel === '0') {
                arr.push({ ... params, id: v.id })
              }
            }
          })
        }else {
          params['id'] = id;
        }
        if(type === 1) {
          if(!arr.length) return ElMessage({message: '选择的数据已审核', type: 'warning' });
        }
        personCheckAll(type === 1?arr:[params]);
      })
      .catch(() => {})
}
// 审核
const personCheckAll = (params) => {
  const loading = ElLoading.service({lock: true, text: 'Loading', background: 'rgba(0, 0, 0, 0.7)'});
  _personCheckAll(params)
      .then(res => {
        console.log(res);
        loading.close();
        if(res.data.ok) {
          ElMessage({message: '审核成功', type: 'success' });
          getCheckList();
        }
      })
      .catch(err => {
        console.log(err);
        loading.close();
      })
}

// 菜单选择
const menuSelect = (item) => {
  console.log(item);
  defaultActive.value = item;
  searchValue.value = '';
  keyword.value = '';
  isOperation.value = true;
  getCheckList();
}
// 查看详情
const details = (id) => {
  personId.value = id;
  showDetails.value = true;
}
// 修改人员信息
const editInfo = (id) => {
  router.push({ path: '/index/addCar',query:{ templateId: templateValue.value.id,personId:id,type:templateValue.value.cert.type,editTow:true }})
}
// 监听详情弹框关闭
const showDetailsEmit = () => {
  showDetails.value = false;
}
// 获取证件待审数量
const getUnapproved = () => {
  let role = '0';
  if(oneFlag.value === 'true'&&twoFlag.value === 'false'&&threeFlag.value === 'false') { // 一审
    role = 1;
  }
  if(oneFlag.value === 'false'&&twoFlag.value === 'true'&&threeFlag.value === 'false') { // 二审
    role = 2;
  }
  if(oneFlag.value === 'false'&&twoFlag.value === 'false'&&threeFlag.value === 'true') { // 三审
    role = 3;
  }
  _getUnapproved(loginId,role,'2')
      .then(res => {
        console.log(res);
        if(res.data.ok) {
          let data = res.data.data;
          checkNumber.value = data;
        }
      })
      .catch(err => {
        console.log(err);
      })
}
const showExport = ref(false); // 背审导出弹框显示
const auditState = ref('0'); // 选择的导出背审状态
const exprotClose = () => {
  showExport.value = false;
}
// 批量导出
const auditExitData = () => {
  // showExport.value = true;
  /*let params = {

  }
  _exitData()
      .then(res => {
        console.log(res);
      })
      .catch(err => {
        console.log(err);
      })*/
}
// 背审导出确定
const exportConfirm = () => {
  console.log(templateValue.value);
  let params = {
    templateId:templateValue.value.id,
    exhibitionId,
    bsState:auditState.value
  }
  _exitTemplate(params)
      .then(res => {
        console.log(res);
        if(res.data.ok) {
          let DATA = res.data.data;
          if(DATA.length <= 0) return ElMessage.warning('查询数据为空');
          if(templateValue.value.templateName === '安保证' || templateValue.value.templateName === '工作证') {
            domesticExport(DATA)
          }else{
            overseasExport(DATA)
          }
          showExport.value = false
        }
      })
      .catch(err => {
        console.log(err);
      })
}
//证件注销
const cardCancel = () => {
  if(!selectList.data.length) return ElMessage({message: '请选择注销的数据', type: 'warning' });
  ElMessageBox.confirm(
      '此操作不可逆，是否确认注销此证件?',
      '提示',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }
  )
      .then(() => {
        const loading = ElLoading.service({lock: true, text: 'Loading', background: 'rgba(0, 0, 0, 0.7)'});
        let arr = [];
        selectList.data.forEach(v => {
          arr.push({id: v.id })
        })
        _cardCancel('1',arr)
            .then(res => {
              console.log(res);
              loading.close();
              if(res.data.ok) {
                getCheckList();
                ElMessage({message: res.data.msg||'证件注销成功', type: 'warning' });
              }
            })
            .catch(err => {
              console.log(err);
              loading.close();
            })
      })
      .catch(() => {})
}

// 发证
const sendCard = () => {
  if(!selectList.data.length) return ElMessage({message: '请选择发证的数据', type: 'warning' });
  ElMessageBox.confirm(
      '此操作不可逆，是否确认发证?',
      '提示',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }
  )
      .then(() => {
        const loading = ElLoading.service({lock: true, text: 'Loading', background: 'rgba(0, 0, 0, 0.7)'});
        let arr = [];
        selectList.data.forEach(v => {
          if(v.state === '4') {
            arr.push({id: v.id })
          }
        })
        if(!arr.length) return ElMessage({message: '没有可发证数据', type: 'success' });
        _sendCardUpdate(arr)
            .then(res => {
              console.log(res);
              loading.close();
              if(res.data.ok) {
                getCheckList();
                ElMessage({message: res.data.msg||'发证成功', type: 'success' });
              }else {
                ElMessage({message: res.data.msg||'发证异常', type: 'warning' });
              }
            })
            .catch(err => {
              console.log(err);
              loading.close();
            })
      })
      .catch(() => {})
}

// 操作查询
const searchOption = () => {
  searchValue.value = '';
  keyword.value = '';
  isOperation.value = true;
  getCheckList()
}
// 操作重置
const resetSearchOption = () => {
  searchValue.value = '';
  keyword.value = '';
  isOperation.value = true;
  keywordData.value = '';
  keywordValue.value = '';
  getCheckList()
}
</script>

<style lang="scss" scoped>
.trade-container{
  padding: 10px;
}
.icon-style{
  font-size: 24px;
  cursor: pointer;
}
.face-img-box{
  width: 50px;
  height: 65px;
}
</style>
